import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

// 时间格式转换
String messageTime(num timestamp){
  var date = new DateTime.fromMillisecondsSinceEpoch(timestamp);
  var format = new DateFormat('yyyy-MM-dd HH:mm:ss');
  return  format.format(date);
}

class MessageRow extends StatelessWidget {

  final bool borderBottom = true;
  final String nickName;
  final String message;
  final num time;

  MessageRow({this.nickName, this.message, this.time});

  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Container(
          padding: const EdgeInsets.symmetric(
            horizontal: 10
          ),
          child: Container(
            width: 36,
            height: 36,
            decoration: new BoxDecoration(
              color: Colors.grey,
              borderRadius: BorderRadius.circular(5)
            ),
            child:  ClipRRect(
              borderRadius: BorderRadius.circular(5),
              child: Image.network("https://picsum.photos/120/120"),
            ),
          ),
        ),
        Expanded(
          flex: 1,
          child: Container(
            alignment: Alignment.centerLeft,
            height: 50,
            padding:new EdgeInsets.fromLTRB(5, 5, 5, 0),
            child: Column(
              children: <Widget>[
                // 第一行文本
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    // 名称
                    Text(
                      nickName,
                      style: new TextStyle(
                        fontSize: 13,
                      ),
                    ),
                    Container(
                      height: 20,
                      child: Text(
                        messageTime(time),
                        // DateFormat('yyyy-MM-dd HH:mm:ss').format(time),
                        style: new TextStyle(
                          fontSize: 8,
                          color: Color.fromRGBO(177, 177, 177, 1)
                        ),
                      ),
                    ),
                  ],
                ),
                // 第二行文本
                Container(
                  padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                  child:   Row(
                    children: <Widget>[
                      // 最新消息
                      Text(
                        message,
                        overflow: TextOverflow.ellipsis,
                        style: new TextStyle(
                          fontSize: 9,
                          color: Color.fromRGBO(177, 177, 177, 1)
                        )
                      )
                    ],
                  ),
                )
              ],
            ),
            decoration: BoxDecoration(
              border:Border(bottom:BorderSide(width: 1,color: Color(0xffe5e5e5)) )
            )
          ),
        )
        
      ],
    );
  }
}